package com.zhongxing.hdy.spritel_hdy.onTouch;

import android.util.Log;
import android.view.MotionEvent;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.ScaleAnimation;

/**
 * Created by Administrator on 2017年6月30日 0030.
 */

public class MainOnTouch implements View.OnTouchListener {

    private static MainOnTouch instance =null;

    private MainOnTouch() {

    }

    public static MainOnTouch getInstance() {
        if (instance == null) {
            synchronized (MainOnTouch.class) {
                if (instance == null) {
                    instance=new MainOnTouch();
                }
            }
        }
        return instance;
    }
    @Override
    public boolean onTouch(View v, MotionEvent event) {
        //获取当前事件的状态
        int action = event.getAction();
        switch (action) {
            case MotionEvent.ACTION_DOWN:{
                Log.i(getClass().getName(), "down");
                /**
                 *     public ScaleAnimation(float fromX, float toX, float fromY, float toY,
                 int pivotXType, float pivotXValue, int pivotYType, float pivotYValue)
                 */
                ScaleAnimation scaleAnimation = new ScaleAnimation(1f, 0.75f, 1.f, 0.75f,
                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.75f);
                scaleAnimation.setDuration(300);//持续时间
                scaleAnimation.setFillAfter(true);//保持动画执行完的状态;
                v.startAnimation(scaleAnimation);
                break;
            }case MotionEvent.ACTION_MOVE:{
                Log.i(getClass().getName(), "move");
                break;
            }case MotionEvent.ACTION_UP:{
                Log.i(getClass().getName(), "up");
                ScaleAnimation scaleAnimation = new ScaleAnimation(0.75f, 1.f, 0.75f,1f,
                        Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.75f);
                scaleAnimation.setDuration(300);//持续时间
                scaleAnimation.setFillAfter(true);//保持动画执行完的状态;
                v.startAnimation(scaleAnimation);
                break;
            }
        }
        return true;
    }
}
